package com.zbkj.service.assistant.service;


import cn.hutool.core.util.ObjUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zbkj.common.model.assistant.AssistantQuestion;
import com.zbkj.service.assistant.dao.AssistantQuestionDao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.service.assistant.model.request.AssistantQuestionSearchRequest;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AssistantQuestionBaseServiceImpl extends ServiceImpl<AssistantQuestionDao, AssistantQuestion> {

    public PageInfo<AssistantQuestion> getPage(AssistantQuestionSearchRequest request) {
        PageHelper.startPage(request.getPage(), request.getLimit());
        List<AssistantQuestion> list = super.lambdaQuery()
            .and(ObjUtil.isNotEmpty(request.getKeywords()), qw -> qw.like(AssistantQuestion::getTitle, request.getKeywords())
                .or().like(AssistantQuestion::getContent, request.getKeywords()))
            .ge(ObjUtil.isNotEmpty(request.getStartTime()), AssistantQuestion::getCreateTime, request.getStartTime())
            .le(ObjUtil.isNotEmpty(request.getEndTime()), AssistantQuestion::getCreateTime, request.getEndTime())
            .orderByAsc(AssistantQuestion::getSort)
            .list();
        return new PageInfo<>(list);
    }
}

